package com.room.search.service;

import com.room.search.domain.RoomUserBrokerChatList;
import com.room.search.repository.RoomUserBrokerChatListRepository;
import com.room.search.service.dto.RoomUserBrokerChatListDTO;
import com.room.search.service.mapper.RoomUserBrokerChatListMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link RoomUserBrokerChatList}.
 */
@Service
@Transactional
public class RoomUserBrokerChatListService {

    private final Logger log = LoggerFactory.getLogger(RoomUserBrokerChatListService.class);

    private final RoomUserBrokerChatListRepository roomUserBrokerChatListRepository;

    private final RoomUserBrokerChatListMapper roomUserBrokerChatListMapper;

    public RoomUserBrokerChatListService(
        RoomUserBrokerChatListRepository roomUserBrokerChatListRepository,
        RoomUserBrokerChatListMapper roomUserBrokerChatListMapper
    ) {
        this.roomUserBrokerChatListRepository = roomUserBrokerChatListRepository;
        this.roomUserBrokerChatListMapper = roomUserBrokerChatListMapper;
    }

    /**
     * Save a roomUserBrokerChatList.
     *
     * @param roomUserBrokerChatListDTO the entity to save.
     * @return the persisted entity.
     */
    public RoomUserBrokerChatListDTO save(RoomUserBrokerChatListDTO roomUserBrokerChatListDTO) {
        log.debug("Request to save RoomUserBrokerChatList : {}", roomUserBrokerChatListDTO);
        RoomUserBrokerChatList roomUserBrokerChatList = roomUserBrokerChatListMapper.toEntity(roomUserBrokerChatListDTO);
        roomUserBrokerChatList = roomUserBrokerChatListRepository.save(roomUserBrokerChatList);
        return roomUserBrokerChatListMapper.toDto(roomUserBrokerChatList);
    }

    /**
     * Partially update a roomUserBrokerChatList.
     *
     * @param roomUserBrokerChatListDTO the entity to update partially.
     * @return the persisted entity.
     */
    public Optional<RoomUserBrokerChatListDTO> partialUpdate(RoomUserBrokerChatListDTO roomUserBrokerChatListDTO) {
        log.debug("Request to partially update RoomUserBrokerChatList : {}", roomUserBrokerChatListDTO);

        return roomUserBrokerChatListRepository
            .findById(roomUserBrokerChatListDTO.getId())
            .map(existingRoomUserBrokerChatList -> {
                roomUserBrokerChatListMapper.partialUpdate(existingRoomUserBrokerChatList, roomUserBrokerChatListDTO);

                return existingRoomUserBrokerChatList;
            })
            .map(roomUserBrokerChatListRepository::save)
            .map(roomUserBrokerChatListMapper::toDto);
    }

    /**
     * Get all the roomUserBrokerChatLists.
     *
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public List<RoomUserBrokerChatListDTO> findAll() {
        log.debug("Request to get all RoomUserBrokerChatLists");
        return roomUserBrokerChatListRepository
            .findAll()
            .stream()
            .map(roomUserBrokerChatListMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one roomUserBrokerChatList by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<RoomUserBrokerChatListDTO> findOne(Long id) {
        log.debug("Request to get RoomUserBrokerChatList : {}", id);
        return roomUserBrokerChatListRepository.findById(id).map(roomUserBrokerChatListMapper::toDto);
    }

    /**
     * Delete the roomUserBrokerChatList by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete RoomUserBrokerChatList : {}", id);
        roomUserBrokerChatListRepository.deleteById(id);
    }
}
